package ch.fhnw.kosmonauten.server.net.dto;

import java.io.Serializable;

import ch.fhnw.kosmonauten.model.User;
import ch.fhnw.kosmonauten.server.dal.UserAccessLayer;

/**
 * Diese Klasse wandelt die Benutzer Informationen aus der Datenbank in ein UserObject um.
 * 
 * @author Fabian Siegrist
 * @author Oliver Freiermuth
 * @author Mikhail Onoufrienko
 * @author Risto Milani
 * @version $Revision: 105 $
 *          File name: $HeadURL: http://iching-kosmonauten.googlecode.com/svn/I-Ching/src/ch/fhnw/kosmonauten/server/net/dto/Transformation.java $
 *          Last modified:$Date: 2013-05-24 13:48:02 +0000 (Fri, 24 May 2013) $
 *          Last modified by: $Author: molotok.mihon@gmail.com $
 */

// class definition
@SuppressWarnings("serial")
public class Transformation implements Serializable {

	// attributes
	private User usr;

	// methods
	// The method creates the User Object which is logging in
	/**
	 * @param username
	 * @param password
	 * @return
	 */
	public User getUser(String username, String password) {
		try {
			UserAccessLayer ual = new UserAccessLayer();
			String[] user = ual.checkUser(username, password);
			if (user == null) {
				return null;
			} else if (user.length > 0 && user[0].length() > 0) {
				usr = new User(Integer.parseInt(user[0]), user[1], user[2],
						user[3], user[4]);
				return usr;
			} else {
				usr = new User();
				return usr;
			}
		} catch (Exception e) {
			System.out.println(e.getMessage());
			return null;
		}
	}
}
